package cn.nit.blog.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Created by wjx on 2023/3/21 16:58
 */

/**
 * 用于返回给前端
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {

    private Integer code;

    private String msg;

    private Object data;

    public static Result ok(){
        Result result = new Result();
        result.setCode(200);
        return result;
    }

    public static Result ok(Object data) {
        Result ok = ok();
        ok.setData(data);
        return ok;
    }

    public static Result error(){
        Result error = new Result();
        error.setCode(500);
        return error;
    }
    // 返回错误 并且有消息
    public static Result error(String msg){
        Result error = error();
        error.setMsg(msg);
        return error;
    }

}
